package com.isoft.demo01.controller;

import com.isoft.demo01.bean.ResponseData;
import com.isoft.demo01.bean.ResultCode;
import com.isoft.demo01.entity.GameType;
import com.isoft.demo01.service.impl.GameTypeImplService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RequestMapping("team1/game")
@RestController
public class GameTypeController {
    @Autowired
    GameTypeImplService gameTypeImplServiceSys;
    @GetMapping
    public ResponseData getAll(Boolean isdel){
        List<GameType> list=gameTypeImplServiceSys.getAll(null);
        ResponseData req=new ResponseData();
        req.setErrorCode(ResultCode.SUCCESS.getCode());
        req.setMsg(ResultCode.SUCCESS.getMessage());
        req.setData(list);
        return req;
    }
    @PutMapping("{id}")
    public ResponseData update(@PathVariable("id") Integer typeid,String typename){
        boolean result=gameTypeImplServiceSys.update(typeid, typename);
        ResponseData req=new ResponseData();
        if (result){
            req.setErrorCode(ResultCode.SUCCESS.getCode());
            req.setMsg(ResultCode.SUCCESS.getMessage());

        }else {
            req.setErrorCode(ResultCode.COMMON_FAIL.getCode());
            req.setMsg(ResultCode.COMMON_FAIL.getMessage());
        }
        req.setData(result);
        return req;

    }
    @PostMapping
    public ResponseData add(String typename){
        boolean result=gameTypeImplServiceSys.insert(typename);
        ResponseData req=new ResponseData();
        if (result){
            req.setErrorCode(ResultCode.SUCCESS.getCode());
            req.setMsg(ResultCode.SUCCESS.getMessage());
        }else {
            req.setErrorCode(ResultCode.COMMON_FAIL.getCode());
            req.setMsg(ResultCode.COMMON_FAIL.getMessage());
        }
        req.setData(result);
        return  req;
    }
    @PutMapping("/updateisdel")
    public ResponseData updateisdel(Integer typeid,Boolean isdel){
        boolean result=gameTypeImplServiceSys.updetadel(typeid, isdel);
        ResponseData req=new ResponseData();
        if (result){
            req.setErrorCode(ResultCode.SUCCESS.getCode());
            req.setMsg(ResultCode.SUCCESS.getMessage());
        }else {
            req.setErrorCode(ResultCode.COMMON_FAIL.getCode());
            req.setMsg(ResultCode.COMMON_FAIL.getMessage());
        }
        req.setData(result);
        return req;
    }
}
